package com.theydream.qeechain.publicmethod;

import java.util.HashMap;
import java.util.Map;

import com.theydream.qeechain.globaldata.GlobalData;

import android.hardware.Camera;

public class PublicMethod {
	static void openCamera(Camera cam)
	{
		cam.open();
	}
	
	public static Map<String, String> parseStringToMap(String str)	{
		Map<String, String> map = new HashMap<String, String>();
		for (String subStr : str.split(";"))	{
			String [] subStrPair = subStr.split(","); 
			map.put(subStrPair[0], subStrPair[1]);
		}
		return map;
	}
	
	public static Map<String, Integer> parseAttr(String attr)	{
		Map<String, Integer> map = new HashMap<String, Integer>();
		String [] arr = attr.split(";");
		map.put("S", Integer.valueOf(arr[0]));
		map.put("P", Integer.valueOf(arr[1]));
		map.put("E", Integer.valueOf(arr[2]));
		map.put("C", Integer.valueOf(arr[3]));
		map.put("I", Integer.valueOf(arr[4]));
		map.put("A", Integer.valueOf(arr[5]));
		map.put("L", Integer.valueOf(arr[6]));		
		return map;
	}
	
	public static Map<String, Integer> generateStat(Map<String, Integer> attr)	{
		Map<String, Integer> map = new HashMap<String, Integer>();
		Integer S = attr.get("S");
//		Integer P = attr.get("P");
		Integer E = attr.get("E");
//		Integer C = attr.get("C");
//		Integer I = attr.get("I");
		Integer A = attr.get("A");
		Integer L = attr.get("L");
		
		map.put("HP", E*25 + 100);
		map.put("AP", A*5 + 60);
		map.put("DMG", S*2);
		map.put("DR", (int)((0.4*A+0.6*E)*0.75));
		map.put("SPEED", 15-A);
		map.put("CRIT", L*3);
		
		return map;
	}
	
	public static String buildAttrStr(Map<String,Integer> attr)	{
		String str = "";
		for (Map.Entry<String, Integer> entry : attr.entrySet())	{
			str += entry.getValue().toString();
			str += ";";
		}
		str.substring(0, str.length()-2);
		return str;
	}
	
	public static boolean canFightBoss()	{
		if (GlobalData.getInstance().getDbhelper().getUnlockerTotal()>GlobalData.getInstance().getDbhelper().getUnlocker().size())
			return false;
		return true;
	}
}
